package org.xm.sk.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.xm.sk.vo.e.BoderStatus;
import org.xm.sk.vo.ob.Boder2User;
import org.xm.sk.vo.ob.BoderPaid;
import org.xm.sk.vo.ob.CmBoder4Hairdresser;
import org.xm.sk.vo.ob.Performance;
import org.xm.sk.vo.ob.ServerTimeInfo;
import org.xm.sk.vo.ob.UnBoder4Hairdresser;
import org.xm.sk.vo.tb.Boder;

@Repository
public interface BoderRepository extends JpaRepository<Boder, Integer>,
        JpaSpecificationExecutor<Boder>, QuerydslPredicateExecutor<Boder> {

    Set<Boder> findByName(String name);
    
    Set<Boder> findByOrdernumIn(Set<String> ordernum);

    @Modifying
    @Query("UPDATE FROM Boder u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id = :id")
    void delete(@Param("id") int id, @Param("userid") int userid,
            @Param("username") String username);

    @Modifying
    @Query("UPDATE FROM Boder u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id in :ids")
    void delete(@Param("ids") Set<Integer> ids, @Param("userid") int userid,
            @Param("username") String username);

    Page<BoderPaid> listPaidByUserId(Pageable arg0, Integer userid,
            BoderStatus status);

    Page<Boder2User> listMakingByUserId(Pageable arg0, Integer userid,
            BoderStatus status);

    Page<UnBoder4Hairdresser> listUnByHairdresserId(Pageable arg0,
            Integer userid, BoderStatus status);

    Page<CmBoder4Hairdresser> listCmByHairdresserId(Pageable arg0,
            Integer userid, BoderStatus status);

    List<Performance> performanceByYear4Hairdresser(Integer hairdresserid,
            Date tag);

    List<Performance> performanceByMonth4Hairdresser(Integer hairdresserid,
            Date tag);

    List<Performance> performanceByDay4Hairdresser(Integer hairdresserid,
            Date tag);

    Long waitCount4Hairdresser(int id, BoderStatus status);

    List<ServerTimeInfo> listServerTime(Integer hairdresserid, BoderStatus status);
    
    Long exBoder(int id, Date mktime, BoderStatus status);

}
